<script setup>
import { ref,computed } from 'vue'
//导入axios
import axios from 'axios'

function loadData() {
  // 向给定ID的用户发起请求
  axios.get('user_1.json',{
    params: {
      ID: 12345
    }
  })
    .then(function (response) {
      // 处理成功情况
      console.log(response);
    })
    .catch(function (error) {
      // 处理错误情况
      console.log(error);
    })
    .finally(function () {
      // 总是会执行
      console.log('请求完毕');
    });
}

function loadDataPost() {
  axios.post('/user_1.json', {
    firstName: 'Fred',
    lastName: 'Flintstone'
  })
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });
}
</script>

<template>
  <h1>AI</h1>
  <p>
    <button @click="loadData()">获取数据</button>
    <button @click="loadDataPost()">获取数据POST</button>
  </p>
</template>

<style scoped>

</style>
